<template>
  <div>
    <template>
      <el-table
        :data="list"
        border
        style="width: 100%; margin-bottom: 20px; margin-top: 20px"
        row-key="id"
        :tree-props="{ children: 'children' }"
      >
        <el-table-column prop="id" label="商品编号" width="100" >
        </el-table-column>
        <el-table-column prop="goodsname" label="商品名称" width="100" >
        </el-table-column>
        <el-table-column prop="price" label="商品价格" width="100" >
        </el-table-column>
        <el-table-column prop="market_price" label="市场价格" width="100" >
        </el-table-column>
        <el-table-column label="图片" >
          <template slot-scope="scope">
            <img class="img1" :src="$pre + scope.row.img" alt="" />
          </template>
        </el-table-column>

        <el-table-column label="是否新品" >
          <template slot-scope="scope">
            <el-button type="primary" v-if="scope.row.isnew == 1"
              >是</el-button
            >
            <el-button type="info" v-else>否</el-button>
          </template>
        </el-table-column>
        <el-table-column label="是否热卖" >
          <template slot-scope="scope">
            <el-button type="primary" v-if="scope.row.ishot == 1"
              >是</el-button
            >
            <el-button type="info" v-else>否</el-button>
          </template>
        </el-table-column>

        <el-table-column label="状态" >
          <template slot-scope="scope">
            <el-button type="primary" v-if="scope.row.status == 1"
              >启用</el-button
            >
            <el-button type="info" v-else>禁用</el-button>
          </template>
        </el-table-column>

        <el-table-column prop="name" label="操作" >
          <template slot-scope="scope">
            <el-button type="primary" @click="willEdit(scope.row.id)"
              >编辑</el-button
            >
            <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>
</div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { reqgoodsdelete } from "../../../http/api";
import { successAlert } from "../../../utils/alert";
export default {
  props: [],
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      list: "goods/list",
    }),
  },
  mounted() {
    this.reqList();
    this.reqTotal;
  },
  methods: {
    ...mapActions({
      reqList: "goods/reqList",
      reqTotal: "goods/reqTotal",
    }),
    //编辑
    willEdit(id) {
      this.$emit("willEdit", id);
    },
    //删除
    del(id) {
      this.$confirm("你确定要删除吗?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //点了确定的逻辑
          reqgoodsdelete({ id: id }).then((res) => {
            if (res.data.code === 200) {
              successAlert(res.data.msg);
              this.reqList();
              this.reqTotal();
            }
          });
        })
        .catch(() => {
        });
    },
  },
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
.img1 {
  width: 100px;
  height: 100px;
}
</style>